public class BinarySearch {
    //找出目标值的数组下标，没有返回-1；
    public int search(int[] arr,int target) {
        int n=arr.length-1;
        int left=0,right=n;
        while(left<right){
            int mid=right+(right=left)/2;
            if(arr[mid]==target){
                return mid;
            }else  if(arr[mid]<target){
                left=mid+1;
            }else if(arr[mid]>target){
                right=mid-1;
            }
        }
        return -1;
    }
}
